<template>
  <div class="app-container">

    <div class="" style="background: #ffffff; padding: 20px">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
        <el-form-item label="活动名" prop="activityName">
          <el-input
            v-model="queryParams.activityName"
            placeholder="请输入活动名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!--      <el-form-item label="封面URL" prop="cover">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.cover"-->
        <!--          placeholder="请输入封面URL"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <el-form-item label="活动开始时间" prop="startDatetime">
          <el-date-picker clearable
                          v-model="queryParams.startDatetime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择活动开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="活动结束时间" prop="endDatetime">
          <el-date-picker clearable
                          v-model="queryParams.endDatetime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择活动结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报名截止时间" prop="signEndDatetime">
          <el-date-picker clearable
                          v-model="queryParams.signEndDatetime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择报名截止时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总人数限制" prop="maxCount">
          <el-input
            v-model="queryParams.maxCount"
            placeholder="请输入总人数限制"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="活动地点" prop="address">
          <el-input
            v-model="queryParams.address"
            placeholder="请输入活动地点"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="积分" prop="point">
          <el-input
            v-model="queryParams.point"
            placeholder="请输入积分"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="队伍" prop="teamId">
          <el-select v-model="queryParams.teamId" filterable placeholder="请选择">
            <el-option
              v-for="item in duiwoptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['activity:management:add']"
          >新增
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['activity:management:remove']"
          >删除
          </el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
    </div>

    <div class="" style="background: #ffffff; padding: 20px; margin: 20px 0 0">
      <el-table :data="activityList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"/>
        <!--      <el-table-column label="主键" align="center" prop="pkId" />-->
        <el-table-column label="活动名" align="center" prop="activityName"/>
        <el-table-column label="封面图片" align="center" prop="cover">
          <template slot-scope="scope">
            <el-image
              style="width: 100px; height: 100px"
              :src="scope.row.cover"
              fit="fit"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column label="活动开始时间" align="center" prop="startDatetime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startDatetime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="活动结束时间" align="center" prop="endDatetime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endDatetime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="报名截止时间" align="center" prop="signEndDatetime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.signEndDatetime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="总人数限制" align="center" prop="maxCount"/>
        <el-table-column label="条件说明" align="center" prop="conditionRequire"/>
        <!--      <el-table-column label="活动介绍" align="center" prop="description" />-->
        <el-table-column label="活动地点" align="center" prop="address"/>
        <el-table-column label="活动状态" align="center" prop="status">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status==0">未通过</el-tag>
            <el-tag v-if="scope.row.status==1">审核中</el-tag>
            <el-tag v-if="scope.row.status==2">审核通过</el-tag>
            <el-tag v-if="scope.row.status==3">截止报名</el-tag>
            <el-tag v-if="scope.row.status==4">已结束</el-tag>
          </template>
        </el-table-column>
<!--        <el-table-column label="积分" align="center" prop="workHour"/>-->
        <el-table-column width="180" label="审核" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              :disabled="scope.row.status!='1'"
              size="small"
              type="primary"
              @click="handleUpdatepass(scope.row)"
              v-hasPermi="['activity:management:pass']"
            >同意
            </el-button>
            <el-button
              :disabled="scope.row.status!=='1'"
              size="small"
              type="danger"
              @click="handleDeletedeny(scope.row)"
              v-hasPermi="['activity:management:deny']"
            >拒绝
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['activity:management:edit']"
            >修改
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['activity:management:remove']"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="currten.pageNum"
        :limit.sync="currten.pageSize"
        @pagination="getList"
      />
    </div>

    <!-- 添加或修改活动列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="封面图片:" prop="cover">
          <el-upload
            class="avatar-uploader"
            action
            :http-request="selectPicUpload"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="form.cover" :src="form.cover" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-row>
          <el-col :span="24">
            <el-form-item label="活动名:" prop="activityName">
              <el-input class="input" v-model="form.activityName" placeholder="请输入活动名"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="活动开始时间:" prop="startDatetime">
              <el-date-picker clearable
                              v-model="form.startDatetime"
                              type="datetime"
                              default-time="12:00:00"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择活动开始时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="活动结束时间:" prop="endDatetime">
              <el-date-picker clearable
                              v-model="form.endDatetime"
                              type="datetime"
                              default-time="12:00:00"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择活动结束时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="总人数限制:" prop="maxCount">
              <el-input class="input" v-model="form.maxCount" placeholder="请输入总人数限制"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报名截止时间:" prop="signEndDatetime">
              <el-date-picker clearable
                              v-model="form.signEndDatetime"
                              type="datetime"
                              default-time="12:00:00"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择报名截止时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="主办方" prop="organizer">
              <el-input class="input" v-model="form.organizer[0].name" placeholder="请输入主办方名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="队伍选择:" prop="teamId">
              <el-select v-model="form.teamId" @change="teamList" filterable placeholder="请选择">
                <el-option
                  v-for="item in duiwoptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人:" prop="maxCount">
              <el-input class="input" v-model="form.organizer[0].linkmanName" placeholder="请输入联系人姓名"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话:" prop="workHour">
              <el-input class="input" v-model="form.organizer[0].phone" placeholder="请输入主办方手机号"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="活动地点:" prop="address">
          <el-input v-model="form.address" placeholder="请输入活动地点"/>
        </el-form-item>
        <el-form-item label="条件说明:" prop="conditionRequire">
          <el-input v-model="form.conditionRequire" type="textarea" :rows="3" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="活动介绍:" prop="description">
          <el-input v-model="form.description" type="textarea" :rows="3" placeholder="请输入内容" width="200px"/>
        </el-form-item>
        <el-form-item label="服务种类:" prop="serviceCategory">
          <el-checkbox-group v-model="checkList1">
            <el-checkbox v-for="item in categorylist[0]" @change="checkList" :label="item.name"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="服务对象:" prop="serviceObject">
          <el-checkbox-group v-model="checkList2">
            <el-checkbox v-for="item in categorylist[1]" :label="item.name"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="志愿者保障:" prop="serviceCategory">
          <el-checkbox-group v-model="checkList3">
            <el-checkbox v-for="item in categorylist[2]" :label="item.name"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <div v-if="title !='补录'">
          <el-form-item label="岗位需求:" prop="job">
            <div v-for="(item,index) in form.job" style="display: flex;margin-top: 30px">
              <div>名称:</div>
              <el-input style="width: 100px;margin-left: 10px" v-model="item.jobName"/>
              <div style="margin-left: 30px">人数:</div>
              <el-input style="width: 100px;margin-left: 10px" v-model="item.jobCount"/>
              <div style="margin-left: 30px">工时:</div>
              <el-input style="width: 100px;margin-left: 10px" v-model="item.workHour"/>
              <div style="margin-left: 30px">积分:</div>
              <el-input style="width: 100px;margin-left: 10px" v-model="item.point"/>
              <!--          删除选项-->
              <el-button style="margin-left: 10px;width: 35px;height: 35px" type="danger" icon="el-icon-delete"
                         size="mini" circle @click="deleteSelect(index,1)"
              ></el-button>
            </div>
          </el-form-item>
          <el-button
            style="margin:-20px 0 0 42px"
            type="primary"
            plain
            size="mini"
            @click="jobAdd(1)"
          >新增岗位
          </el-button>
        </div>
        <div v-if="title =='补录'">
          <el-form-item label="岗位需求:" prop="jobUserVOS">
            <div v-for="(item,index) in form.jobUserVOS">
              <div style="display: flex;margin-top: 30px">
                <div>名称:</div>
                <el-input style="width: 100px;margin-left: 10px" v-model="item.jobName"/>
                <div style="margin-left: 30px">工时:</div>
                <el-input style="width: 100px;margin-left: 10px" v-model="item.workHour"/>
                <div style="margin-left: 30px">积分:</div>
                <el-input style="width: 100px;margin-left: 10px" v-model="item.pointPercent"/>
                <!--          删除选项-->
                <el-button style="margin-left: 10px;width: 35px;height: 35px" type="primary" icon="el-icon-user"
                           size="mini" circle @click="AddSelect(index)"
                ></el-button>
                <el-button style="margin-left: 10px;width: 35px;height: 35px" type="danger" icon="el-icon-delete"
                           size="mini" circle @click="deleteSelect(index,4)"
                ></el-button>
              </div>
              <div v-for="(n,p) in item.jobUsers" style="display: flex;margin-top: 30px">
                <div>志愿者:</div>
                <el-select v-model="n.userId" filterable placeholder="请选择">
                  <el-option
                    v-for="item in userList"
                    :key="item.uid"
                    :label="item.realName"
                    :value="item.uid"
                  >
                  </el-option>
                </el-select>
                <div style="margin-left: 30px">工时:</div>
                <el-input style="width: 100px;margin-left: 10px" v-model="n.workHour"/>
                <el-button style="margin-left: 10px;width: 35px;height: 35px" type="danger" icon="el-icon-delete"
                           size="mini" circle @click="deleteUser(index,p)"
                ></el-button>
              </div>
            </div>
          </el-form-item>
          <el-button
            style="margin:-20px 0 0 42px"
            type="primary"
            plain
            size="mini"
            @click="jobAdd(4)"
          >新增岗位
          </el-button>
        </div>
        <!--        新增特色-->
        <div style="display: flex">
          <div>
            <el-form-item label="活动特色:" prop="feature">
              <div v-for="(item,index) in form.feature" style="display: flex;margin-top: 30px">
                <div>特色名称:</div>
                <el-input style="width: 100px;margin-left: 10px" v-model="item.name"/>
                <!--          删除选项-->
                <el-button style="margin-left: 10px;width: 35px;height: 35px" type="danger" icon="el-icon-delete"
                           size="mini" circle @click="deleteSelect(index,2)"
                ></el-button>
              </div>
            </el-form-item>
            <el-button
              style="margin:-10px 0 0 42px"
              type="primary"
              plain
              size="mini"
              @click="jobAdd(2)"
            >新增特色
            </el-button>
          </div>
        </div>
        <div>
          <el-form-item label="举办场次:" prop="organizer">
            <div v-for="(item,index) in form.session">
              <div style="display: flex;margin-top: 20px">
                <div style="margin-left: 30px;">场次名称:</div>
                <el-input style="width: 100px;margin-left: 10px" v-model="item.sessionName"/>
                <el-button style="margin-left: 300px;width: 35px;height: 35px" type="danger" icon="el-icon-delete"
                           size="mini" circle @click="deleteSelect(index,3)"
                ></el-button>
              </div>
              <div style="display: flex;margin-top: 20px">
                <div style="margin-left: 30px">开始时间：</div>
                <el-date-picker
                  v-model="item.startDatetime"
                  type="datetime"
                  placeholder="选择日期时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  default-time="12:00:00"
                >
                </el-date-picker>
                <div style="margin-left: 30px">结束时间：</div>
                <el-date-picker
                  v-model="item.endDatetime"
                  type="datetime"
                  placeholder="选择日期时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  default-time="12:00:00"
                >
                </el-date-picker>

              </div>

              <!--          删除选项-->
            </div>
          </el-form-item>
          <el-button
            style="margin:-10px 0 0 42px"
            type="primary"
            plain
            size="mini"
            @click="jobAdd(3)"
          >新增场次
          </el-button>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listActivity,
  getActivity,
  delActivity,
  addActivity,
  updateActivity,
  uploadPic,
  deljob,
  deny, pass, activitynormalList
} from '@/api/activity/activity'
import { imgUrl } from '@/utils/request'
import { listUser, teamlist } from '@/api/user/user'

export default {
  name: 'Activity',
  data() {
    return {
      // 图片前缀
      imgUrl: imgUrl,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 活动列表表格数据
      activityList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      // for
      currten: {
        pageNum: 1,
        pageSize: 10
      },
      userqueryParams: {
        // pkId: null,
        // phone: null,
        // nickName: null,

        realName: null,
        role: 1,
        teamId: null,
        account: null,
        contactAddress: null

        // company: null,
        // politicalIdentityId: null,
        // joinDescription: null,
        // avatar: null,
        // point: null,
        // workHours: null,
        // idNumber: null,
        // birthDate: null,
        // sex: null,
        // forte: null
      },
      //分页
      column: {
        pageSize: null,
        pageNum: null
      },
      queryParams: {
        activityName: null,
        cover: null,
        startDatetime: null,
        endDatetime: null,
        signEndDatetime: null,
        maxCount: null,
        conditionRequire: null,
        description: null,
        address: null,
        status: null,
        job: null,
        teamId: null,
        session: null,
        feature: null,
        welfare: null,
        organizer: null,
        point: null
      },
      // 志愿者列表
      userList: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cover: [
          { required: true, message: '请输入活动图片', trigger: 'change' }
        ],
        teamId: [
          { required: true, message: '必须选择活动队伍', trigger: 'change' }
        ],
        serviceCategory: [
          { required: true, message: '请选择服务种类', trigger: 'change' }
        ],
        serviceObject: [
          { required: true, message: '请选择服务对象', trigger: 'change' }
        ],
        serviceSafeguard: [
          { required: true, message: '请选择志愿者保障', trigger: 'change' }
        ],
        activityName: [
          { required: true, message: '请输入活动名称', trigger: 'change' }
        ],
        maxCount: [
          { required: true, message: '最大人数不能为空', trigger: 'change' }
        ],
        endDatetime: [
          { required: true, message: '活动结束时间必须选择', trigger: 'change' }
        ],
        startDatetime: [
          { required: true, message: '活动开始时间不能为空', trigger: 'change' }
        ],
        description: [
          { required: true, message: '活动开始内容不能为空', trigger: 'change' }
        ],
        address: [
          { required: true, message: '地点不能为空', trigger: 'change' }
        ],
        conditionRequire: [
          { required: true, message: '请输入条件说明', trigger: 'change' }
        ],
        signEndDatetime: [
          { required: true, message: '活动截止时间必须选择', trigger: 'change' }
        ],
        job: [
          { type: 'array', required: true, message: '请添加岗位需求', trigger: 'change' }
        ],
        feature: [
          { type: 'array', required: true, message: '请添加活动特色', trigger: 'change' }
        ],
        session: [
          { type: 'array', required: true, message: '请添加活动场次', trigger: 'change' }
        ]
      },
      duiwoptions: [],
      // 种类列表
      categorylist: [],
      checkList1: [],
      checkList2: [],
      checkList3: []
    }
  },
  created() {
    this.getcategory()
    this.getList()
    this.gettemn()
    this.reset()
  },
  methods: {
    // 获取队伍
    gettemn() {
      teamlist().then(res => {
        this.duiwoptions = res
        console.log(this.duiwoptions)
      })
    },
    // 表单
    getcategory() {
      activitynormalList().then(res => {
        this.categorylist = res
      })
    },
    /** 查询活动列表列表 */
    getList() {
      this.loading = true
      listActivity(this.queryParams, this.currten).then(response => {
        this.activityList = response.pageData
        this.total = Number(response.total)
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        jobUserVOS: [],
        activityName: null,
        cover: null,
        startDatetime: null,
        endDatetime: null,
        signEndDatetime: null,
        maxCount: 0,
        conditionRequire: null,
        description: null,
        address: null,
        status: null,
        job: [],
        teamId: null,
        session: [],
        feature: [],
        welfare: [],
        serviceCategory: [{
          id: 0,
          name: '',
          prefix: ''
        }],
        serviceObject: [{
          id: 0,
          name: '',
          prefix: ''
        }],
        serviceSafeguard: [{
          id: 0,
          name: '',
          prefix: ''
        }],
        organizer: [
          {
            id: 0,
            name: '',
            prefix: '',
            linkmanName: '',
            phone: ''
          }
        ],
        workHour: 0
      }
    },
    checkList(e) {
      console.error(e)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams={
        activityName: null,
        cover: null,
        startDatetime: null,
        endDatetime: null,
        signEndDatetime: null,
        maxCount: null,
        conditionRequire: null,
        description: null,
        address: null,
        status: null,
        job: null,
        teamId: null,
        session: null,
        feature: null,
        welfare: null,
        organizer: null,
        point: null
      },
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pkId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加活动列表'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const pkId = row.pkId || this.ids
      getActivity(pkId).then(response => {
        this.form = response
        if (this.form.serviceCategory != null){
          this.checkList1 = this.form.serviceCategory.map(item =>(item.name))
        }
        if (this.form.serviceObject != null){
          this.checkList2 = this.form.serviceObject.map(item =>(item.name))
        }
        if (this.form.serviceSafeguard != null){
          this.checkList3 = this.form.serviceSafeguard.map(item =>(item.name))
        }


        this.open = true
        this.title = '修改活动列表'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.form.serviceCategory = this.categorylist[0].filter(item => this.checkList1.includes(item.name))
        .map(item => ({ name: item.name, id: item.pkId, prefix: '' }))
      this.form.serviceObject = this.categorylist[1].filter(item => this.checkList2.includes(item.name))
        .map(item => ({ name: item.name, id: item.pkId, prefix: '' }))
      this.form.serviceSafeguard = this.categorylist[2].filter(item => this.checkList3.includes(item.name))
        .map(item => ({ name: item.name, id: item.pkId, prefix: '' }))
      console.log(this.checkList1, '112121212', this.form.serviceCategory)
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.pkId != null) {
            updateActivity(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addActivity(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pkIds = row.pkId || this.ids
      this.$modal.confirm('是否确认删除该活动？').then(function() {
        return delActivity(pkIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.title = '补录'
      this.open = true
    },
    // 上传图片
    selectPicUpload(obj) {
      console.log(obj)
      let fd = new FormData() //参数的格式是formData格式的
      fd.append('file', obj.file) //参数
      console.log(fd)
      uploadPic(fd, { modularName: 'ACTIVITY' }).then(res => {
        this.form.cover = res
      })
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isLt2M
    },
    // 岗位新增
    jobAdd(e) {
      if (e === 1) {
        this.form.job.push({
          'id': 0,
          'jobCount': 1,
          'jobName': '',
          'jobRequire': '',
          point:'',
          'jobSignedCount': 0,
          'workHour': 0
        })
      } else if (e === 2) {
        this.form.feature.push(
          {
            'id': 0,
            'name': '',
            'prefix': ''
          })
      } else if (e === 3) {
        this.form.session.push(
          {
            'endDatetime': '',
            'id': 0,
            'sessionName': '',
            'startDatetime': ''
          })
      } else if (e === 4) {
        this.form.jobUserVOS.push(
          {
            'id': 0,
            'jobCount': 0,
            'jobName': '',
            'jobRequire': '',
            'jobUsers': [],
            'pointPercent': 0,
            'workHour': 0
          })
      }
      console.log(this.form.job)
    },
    AddSelect(e) {
      this.form.jobUserVOS[e].jobUsers.push({
        'userId': null,
        'workHour': 0
      })
    },
    // 删除按钮
    deleteSelect(index, e) {
      this.$modal.confirm('是否确认删除此选项?').then(function() {
      }).then(() => {
        if (e === 1) {
          console.error(index, this.title == '添加活动列表')
          if (this.title == '添加活动列表') {
            console.error(index)
            this.form.job.splice(index, 1)
          } else {
            deljob(this.form.job[index].id).then(res => {
              if (res.code === 200) {
                this.form.job.splice(index, 1)
                this.$modal.msgSuccess('删除成功')
              }
            })
          }
        } else if (e === 2) {
          this.form.feature.splice(index, 1)
          this.$modal.msgSuccess('删除成功')
        } else if (e === 3) {
          this.form.session.splice(index, 1)
          this.$modal.msgSuccess('删除成功')
        } else if (e === 4) {
          this.form.jobUserVOS.splice(index, 1)
          this.$modal.msgSuccess('删除成功')
        }
        //如果是服务类型，删掉时间段
        if (this.form.productCategory == 1) {
          this.selectTime.splice(index, 1)
        }

      }).catch(() => {
      })
    },
    // 补录删除志愿者
    deleteUser(e, p) {
      this.form.jobUserVOS[e].jobUsers.splice(p, 1)
      this.$modal.msgSuccess('删除成功')
    },
    handleUpdatepass(e) {
      pass(e.pkId).then(res => {
        if (res.code === 200) {
          this.getList()
          this.$modal.msgSuccess('同意成功')

        }
      })
    },
    handleDeletedeny(e) {
      deny(e.pkId).then(res => {
        if (res.code === 200) {
          this.$modal.msgSuccess('拒绝成功')
        }
      })
    },
    teamList(e) {
      console.error(e)
      this.userqueryParams.teamId = e
      listUser(this.userqueryParams, this.column).then(response => {
        this.userList = response.pageData
      })
    }
  }
}
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}

.avatar {
  width: 120px;
  height: 120px;
  display: block;
}

.input {
  width: 220px;
}
</style>
